const { createStore } = require('redux');

// reducer
function counter(state = 0, action) {
  switch(action.type) {
    case 'INCREMENT': return state + 1;
    case 'DECREMENT': return state - 1;
    default: return state;
  }
}

let store = createStore(counter);
store.subscribe(() => {
  console.log(store.getState());
});

store.dispatch({
  type: 'INCREMENT'
});

store.dispatch({
  type: 'INCREMENT'
});

store.dispatch({
  type: 'DECREMENT'
});

// reducer
function filter(state = {}, action) {
  if(action.type === 'ADD') {
    action.name && action.value && (state[action.name] = action.value);
  } else if (action.type === 'DEL') {
    action.name && delete state[action.name];
  }
}

let objStore = createStore(filter);
objStore.subscribe(() => {
  console.log(objStore.getState());
});

objStore.dispatch({
  type: 'ADD',
  name: 'first',
  value: 'yes'
});

objStore.dispatch({
  type: 'DEL',
  name: 'first'
});